package com.gaoyang.thread;

import com.gaoyang.util.DateUtils;
import com.gaoyang.util.HttpUtils4Black;
import org.springframework.scheduling.annotation.Async;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

@Async
public class MinshengThread implements Callable {

    String username = "";
    String userKey = "";
    String cmbc_uuid = "";
    String code = "";


    String THURSDAY_GIFT = "G201705057259";
    String FRIDAY_GIFT = "G201705057260";
    String SATURDAY_GIFT = "G201705057261";
    String SUNDAY_GIFT = "G201705057262";
    String MONDAY_GIFT = "G201702078122";

    public MinshengThread(String username, String userKey, String cmbc_uuid, String code) {
        this.username = username;
        this.userKey = userKey;
        this.cmbc_uuid = cmbc_uuid;
        this.code = code;
    }

    @Override
    public String call() throws Exception {
        Map<String, String> paramMap = new HashMap();
        String channelType = "activityday";
        String actyId = "A20170505897";
        String giftId = "";
        if (DateUtils.getWeekOfDate().equals("星期五")) {
            giftId = FRIDAY_GIFT;
        } else if (DateUtils.getWeekOfDate().equals("星期四")) {
            giftId = THURSDAY_GIFT;
        } else if (DateUtils.getWeekOfDate().equals("星期六")) {
            giftId = SATURDAY_GIFT;
        } else if (DateUtils.getWeekOfDate().equals("星期日")){
            giftId = SUNDAY_GIFT;
        } else {
            channelType = "";
            actyId = "A20170206786";
            giftId = MONDAY_GIFT;
        }
        paramMap.put("channelType", channelType);
        paramMap.put("actyId", actyId);
        paramMap.put("giftId", giftId);
        paramMap.put("giftNum", "1");
        paramMap.put("groupId", "");
        paramMap.put("isCaptcha", "true");
        paramMap.put("jcaptchaText", code);
//        System.out.println(paramMap.get("jcaptchaText"));
        paramMap.put("merchantId", "0007135");
        paramMap.put("timp", "405b150a38f44f4ef489b44c4987927f");
        paramMap.put("userKey", userKey);
        Thread.sleep((int)(Math.random()*3000));
        String returnStr = HttpUtils4Black.sendMinshengGet("https://prefacty.creditcard.cmbc.com.cn/mmc-main-webapp/main/Order.json?", paramMap, cmbc_uuid);
        return username + ":" + returnStr;
    }

}